// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHAPS_CHAPS_ADAPTOR_H_
#define CHAPS_CHAPS_ADAPTOR_H_

#include <string>
#include <vector>

#include <base/macros.h>

#include "chaps/dbus_adaptors/chaps_interface.h"

namespace base {
class Lock;
}

namespace chaps {

class ChapsInterface;
class TokenManagerInterface;

// The ChapsAdaptor class implements the dbus-c++ generated adaptor interface
// and redirects IPC calls to a ChapsInterface instance.  All dbus-c++ specific
// logic, error handling, etc. is implemented here.  Specifically, the
// ChapsInterface instance need not be aware of dbus-c++ or IPC.  This class
// exists because we don't want to couple dbus-c++ with the Chaps service
// implementation.
class ChapsAdaptor : public org::chromium::Chaps_adaptor,
                     public DBus::ObjectAdaptor {
 public:
  ChapsAdaptor(base::Lock* lock,
               ChapsInterface* service,
               TokenManagerInterface* token_manager);
  virtual ~ChapsAdaptor();

  // These methods are generated by the ChromeOS dbus library.
  virtual void OpenIsolate(const std::vector<uint8_t>& isolate_credential_in,
                           std::vector<uint8_t>& isolate_credential_out,  // NOLINT - refs
                           bool& new_isolate_created,  // NOLINT - refs
                           bool& result,  // NOLINT - refs
                           ::DBus::Error& error);  // NOLINT - refs
  virtual void CloseIsolate(const std::vector<uint8_t>& isolate_credential,  // NOLINT - refs
                            ::DBus::Error& error);  // NOLINT - refs
  virtual void LoadToken(const std::vector<uint8_t>& isolate_credential,
                         const std::string& path,
                         const std::vector<uint8_t>& auth_data,
                         const std::string& label,
                         uint64_t& slot_id,  // NOLINT - refs
                         bool& result,  // NOLINT - refs
                         ::DBus::Error& error);  // NOLINT - refs
  virtual void UnloadToken(const std::vector<uint8_t>& isolate_credential,
                           const std::string& path,
                           ::DBus::Error& error);  // NOLINT - refs
  virtual void ChangeTokenAuthData(const std::string& path,
                                   const std::vector<uint8_t>& old_auth_data,
                                   const std::vector<uint8_t>& new_auth_data,
                                   ::DBus::Error& error);  // NOLINT - refs
  virtual void GetTokenPath(const std::vector<uint8_t>& isolate_credential,
                            const uint64_t& slot_id,
                            std::string& path,  // NOLINT - refs
                            bool& result,  // NOLINT - refs
                            ::DBus::Error& error);  // NOLINT - refs
  virtual void SetLogLevel(const int32_t& level,
                           ::DBus::Error& error);  // NOLINT - refs
  virtual void GetSlotList(const std::vector<uint8_t>& isolate_credential,
                           const bool& token_present,
                           std::vector<uint64_t>& slot_list,  // NOLINT - refs
                           uint32_t& result,  // NOLINT - refs
                           ::DBus::Error& error);  // NOLINT - refs
  virtual void GetSlotInfo(const std::vector<uint8_t>& isolate_credential,
                           const uint64_t& slot_id,
                           std::vector<uint8_t>& slot_description,  // NOLINT - refs
                           std::vector<uint8_t>& manufacturer_id,  // NOLINT - refs
                           uint64_t& flags,  // NOLINT - refs
                           uint8_t& hardware_version_major,  // NOLINT - refs
                           uint8_t& hardware_version_minor,  // NOLINT - refs
                           uint8_t& firmware_version_major,  // NOLINT - refs
                           uint8_t& firmware_version_minor,  // NOLINT - refs
                           uint32_t& result,  // NOLINT - refs
                           ::DBus::Error& error);  // NOLINT - refs
  virtual void GetTokenInfo(const std::vector<uint8_t>& isolate_credential,
                            const uint64_t& slot_id,
                            std::vector<uint8_t>& label,  // NOLINT - refs
                            std::vector<uint8_t>& manufacturer_id,  // NOLINT - refs
                            std::vector<uint8_t>& model,  // NOLINT - refs
                            std::vector<uint8_t>& serial_number,  // NOLINT - refs
                            uint64_t& flags,  // NOLINT - refs
                            uint64_t& max_session_count,  // NOLINT - refs
                            uint64_t& session_count,  // NOLINT - refs
                            uint64_t& max_session_count_rw,  // NOLINT - refs
                            uint64_t& session_count_rw,  // NOLINT - refs
                            uint64_t& max_pin_len,  // NOLINT - refs
                            uint64_t& min_pin_len,  // NOLINT - refs
                            uint64_t& total_public_memory,  // NOLINT - refs
                            uint64_t& free_public_memory,  // NOLINT - refs
                            uint64_t& total_private_memory,  // NOLINT - refs
                            uint64_t& free_private_memory,  // NOLINT - refs
                            uint8_t& hardware_version_major,  // NOLINT - refs
                            uint8_t& hardware_version_minor,  // NOLINT - refs
                            uint8_t& firmware_version_major,  // NOLINT - refs
                            uint8_t& firmware_version_minor,  // NOLINT - refs
                            uint32_t& result,  // NOLINT - refs
                            ::DBus::Error& error);  // NOLINT - refs
  virtual void GetMechanismList(const std::vector<uint8_t>& isolate_credential,
                                const uint64_t& slot_id,
                                std::vector<uint64_t>& mechanism_list,  // NOLINT - refs
                                uint32_t& result,  // NOLINT - refs
                                ::DBus::Error& error);  // NOLINT - refs
  virtual void GetMechanismInfo(const std::vector<uint8_t>& isolate_credential,
                                const uint64_t& slot_id,
                                const uint64_t& mechanism_type,
                                uint64_t& min_key_size,  // NOLINT - refs
                                uint64_t& max_key_size,  // NOLINT - refs
                                uint64_t& flags,  // NOLINT - refs
                                uint32_t& result,  // NOLINT - refs
                                ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t InitToken(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& slot_id,
                             const bool& use_null_pin,
                             const std::string& optional_so_pin,
                             const std::vector<uint8_t>& new_token_label,
                             ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t InitPIN(const std::vector<uint8_t>& isolate_credential,
                           const uint64_t& session_id,
                           const bool& use_null_pin,
                           const std::string& optional_user_pin,
                           ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t SetPIN(const std::vector<uint8_t>& isolate_credential,
                          const uint64_t& session_id,
                          const bool& use_null_old_pin,
                          const std::string& optional_old_pin,
                          const bool& use_null_new_pin,
                          const std::string& optional_new_pin,
                          ::DBus::Error& error);  // NOLINT - refs
  virtual void OpenSession(const std::vector<uint8_t>& isolate_credential,
                           const uint64_t& slot_id, const uint64_t& flags,
                           uint64_t& session_id,  // NOLINT - refs
                           uint32_t& result,  // NOLINT - refs
                           ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t CloseSession(const std::vector<uint8_t>& isolate_credential,
                                const uint64_t& session_id,
                                ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t CloseAllSessions(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& slot_id,
      ::DBus::Error& error);  // NOLINT - refs
  virtual void GetSessionInfo(const std::vector<uint8_t>& isolate_credential,
                              const uint64_t& session_id,
                              uint64_t& slot_id,  // NOLINT - refs
                              uint64_t& state,  // NOLINT - refs
                              uint64_t& flags,  // NOLINT - refs
                              uint64_t& device_error,  // NOLINT - refs
                              uint32_t& result,  // NOLINT - refs
                              ::DBus::Error& error);  // NOLINT - refs
  virtual void GetOperationState(const std::vector<uint8_t>& isolate_credential,
                                 const uint64_t& session_id,
                                 std::vector<uint8_t>& operation_state,  // NOLINT - refs
                                 uint32_t& result,  // NOLINT - refs
                                 ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t SetOperationState(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const std::vector<uint8_t>& operation_state,
      const uint64_t& encryption_key_handle,
      const uint64_t& authentication_key_handle,
      ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t Login(const std::vector<uint8_t>& isolate_credential,
                         const uint64_t& session_id,
                         const uint64_t& user_type,
                         const bool& use_null_pin,
                         const std::string& optional_pin,
                         ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t Logout(const std::vector<uint8_t>& isolate_credential,
                          const uint64_t& session_id,
                          ::DBus::Error& error);  // NOLINT - refs
  virtual void CreateObject(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const std::vector<uint8_t>& attributes,
      uint64_t& new_object_handle,  // NOLINT - refs
      uint32_t& result,  // NOLINT - refs
      ::DBus::Error& error);  // NOLINT - refs
  virtual void CopyObject(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const uint64_t& object_handle,
      const std::vector<uint8_t>& attributes,
      uint64_t& new_object_handle,  // NOLINT - refs
      uint32_t& result,  // NOLINT - refs
      ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t DestroyObject(const std::vector<uint8_t>& isolate_credential,
                                 const uint64_t& session_id,
                                 const uint64_t& object_handle,
                                 ::DBus::Error& error);  // NOLINT - refs
  virtual void GetObjectSize(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& session_id,
                             const uint64_t& object_handle,
                             uint64_t& object_size,  // NOLINT - refs
                             uint32_t& result,  // NOLINT - refs
                             ::DBus::Error& error);  // NOLINT - refs
  virtual void GetAttributeValue(const std::vector<uint8_t>& isolate_credential,
                                 const uint64_t& session_id,
                                 const uint64_t& object_handle,
                                 const std::vector<uint8_t>& attributes_in,
                                 std::vector<uint8_t>& attributes_out,  // NOLINT - refs
                                 uint32_t& result,  // NOLINT - refs
                                 ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t SetAttributeValue(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const uint64_t& object_handle,
      const std::vector<uint8_t>& attributes,
      ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t FindObjectsInit(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const std::vector<uint8_t>& attributes,
      ::DBus::Error& error);  // NOLINT - refs
  virtual void FindObjects(const std::vector<uint8_t>& isolate_credential,
                           const uint64_t& session_id,
                           const uint64_t& max_object_count,
                           std::vector<uint64_t>& object_list,  // NOLINT - refs
                           uint32_t& result,  // NOLINT - refs
                           ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t FindObjectsFinal(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t EncryptInit(const std::vector<uint8_t>& isolate_credential,
                               const uint64_t& session_id,
                               const uint64_t& mechanism_type,
                               const std::vector<uint8_t>& mechanism_parameter,
                               const uint64_t& key_handle,
                               ::DBus::Error& error);  // NOLINT - refs
  virtual void Encrypt(const std::vector<uint8_t>& isolate_credential,
                       const uint64_t& session_id,
                       const std::vector<uint8_t>& data_in,
                       const uint64_t& max_out_length,
                       uint64_t& actual_out_length,  // NOLINT - refs
                       std::vector<uint8_t>& data_out,  // NOLINT - refs
                       uint32_t& result,  // NOLINT - refs
                       ::DBus::Error& error);  // NOLINT - refs
  virtual void EncryptUpdate(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& session_id,
                             const std::vector<uint8_t>& data_in,
                             const uint64_t& max_out_length,
                             uint64_t& actual_out_length,  // NOLINT - refs
                             std::vector<uint8_t>& data_out,  // NOLINT - refs
                             uint32_t& result,  // NOLINT - refs
                             ::DBus::Error& error);  // NOLINT - refs
  virtual void EncryptFinal(const std::vector<uint8_t>& isolate_credential,
                            const uint64_t& session_id,
                            const uint64_t& max_out_length,
                            uint64_t& actual_out_length,  // NOLINT - refs
                            std::vector<uint8_t>& data_out,  // NOLINT - refs
                            uint32_t& result,  // NOLINT - refs
                            ::DBus::Error& error);  // NOLINT - refs
  virtual void EncryptCancel(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& session_id,
                             ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t DecryptInit(const std::vector<uint8_t>& isolate_credential,
                               const uint64_t& session_id,
                               const uint64_t& mechanism_type,
                               const std::vector<uint8_t>& mechanism_parameter,
                               const uint64_t& key_handle,
                               ::DBus::Error& error);  // NOLINT - refs
  virtual void Decrypt(const std::vector<uint8_t>& isolate_credential,
                       const uint64_t& session_id,
                       const std::vector<uint8_t>& data_in,
                       const uint64_t& max_out_length,
                       uint64_t& actual_out_length,  // NOLINT - refs
                       std::vector<uint8_t>& data_out,  // NOLINT - refs
                       uint32_t& result,  // NOLINT - refs
                       ::DBus::Error& error);  // NOLINT - refs
  virtual void DecryptUpdate(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& session_id,
                             const std::vector<uint8_t>& data_in,
                             const uint64_t& max_out_length,
                             uint64_t& actual_out_length,  // NOLINT - refs
                             std::vector<uint8_t>& data_out,  // NOLINT - refs
                             uint32_t& result,  // NOLINT - refs
                             ::DBus::Error& error);  // NOLINT - refs
  virtual void DecryptFinal(const std::vector<uint8_t>& isolate_credential,
                            const uint64_t& session_id,
                            const uint64_t& max_out_length,
                            uint64_t& actual_out_length,  // NOLINT - refs
                            std::vector<uint8_t>& data_out,  // NOLINT - refs
                            uint32_t& result,  // NOLINT - refs
                            ::DBus::Error& error);  // NOLINT - refs
  virtual void DecryptCancel(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& session_id,
                             ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t DigestInit(const std::vector<uint8_t>& isolate_credential,
                              const uint64_t& session_id,
                              const uint64_t& mechanism_type,
                              const std::vector<uint8_t>& mechanism_parameter,
                              ::DBus::Error& error);  // NOLINT - refs
  virtual void Digest(const std::vector<uint8_t>& isolate_credential,
                      const uint64_t& session_id,
                      const std::vector<uint8_t>& data_in,
                      const uint64_t& max_out_length,
                      uint64_t& actual_out_length,  // NOLINT - refs
                      std::vector<uint8_t>& digest,  // NOLINT - refs
                      uint32_t& result,  // NOLINT - refs
                      ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t DigestUpdate(const std::vector<uint8_t>& isolate_credential,
                                const uint64_t& session_id,
                                const std::vector<uint8_t>& data_in,
                                ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t DigestKey(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& session_id,
                             const uint64_t& key_handle,
                             ::DBus::Error& error);  // NOLINT - refs
  virtual void DigestFinal(const std::vector<uint8_t>& isolate_credential,
                           const uint64_t& session_id,
                           const uint64_t& max_out_length,
                           uint64_t& actual_out_length,  // NOLINT - refs
                           std::vector<uint8_t>& digest,  // NOLINT - refs
                           uint32_t& result,  // NOLINT - refs
                           ::DBus::Error& error);  // NOLINT - refs
  virtual void DigestCancel(const std::vector<uint8_t>& isolate_credential,
                            const uint64_t& session_id,
                            ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t SignInit(const std::vector<uint8_t>& isolate_credential,
                            const uint64_t& session_id,
                            const uint64_t& mechanism_type,
                            const std::vector<uint8_t>& mechanism_parameter,
                            const uint64_t& key_handle,
                            ::DBus::Error& error);  // NOLINT - refs
  virtual void Sign(const std::vector<uint8_t>& isolate_credential,
                    const uint64_t& session_id,
                    const std::vector<uint8_t>& data,
                    const uint64_t& max_out_length,
                    uint64_t& actual_out_length,  // NOLINT - refs
                    std::vector<uint8_t>& signature,  // NOLINT - refs
                    uint32_t& result,  // NOLINT - refs
                    ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t SignUpdate(const std::vector<uint8_t>& isolate_credential,
                              const uint64_t& session_id,
                              const std::vector<uint8_t>& data_part,
                              ::DBus::Error& error);  // NOLINT - refs
  virtual void SignFinal(const std::vector<uint8_t>& isolate_credential,
                         const uint64_t& session_id,
                         const uint64_t& max_out_length,
                         uint64_t& actual_out_length,  // NOLINT - refs
                         std::vector<uint8_t>& signature,  // NOLINT - refs
                         uint32_t& result,  // NOLINT - refs
                         ::DBus::Error& error);  // NOLINT - refs
  virtual void SignCancel(const std::vector<uint8_t>& isolate_credential,
                          const uint64_t& session_id,
                          ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t SignRecoverInit(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const uint64_t& mechanism_type,
      const std::vector<uint8_t>& mechanism_parameter,
      const uint64_t& key_handle,
      ::DBus::Error& error);  // NOLINT - refs
  virtual void SignRecover(const std::vector<uint8_t>& isolate_credential,
                           const uint64_t& session_id,
                           const std::vector<uint8_t>& data,
                           const uint64_t& max_out_length,
                           uint64_t& actual_out_length,  // NOLINT - refs
                           std::vector<uint8_t>& signature,  // NOLINT - refs
                           uint32_t& result,  // NOLINT - refs
                           ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t VerifyInit(const std::vector<uint8_t>& isolate_credential,
                              const uint64_t& session_id,
                              const uint64_t& mechanism_type,
                              const std::vector<uint8_t>& mechanism_parameter,
                              const uint64_t& key_handle,
                              ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t Verify(const std::vector<uint8_t>& isolate_credential,
                          const uint64_t& session_id,
                          const std::vector<uint8_t>& data,
                          const std::vector<uint8_t>& signature,
                          ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t VerifyUpdate(const std::vector<uint8_t>& isolate_credential,
                                const uint64_t& session_id,
                                const std::vector<uint8_t>& data_part,
                                ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t VerifyFinal(const std::vector<uint8_t>& isolate_credential,
                               const uint64_t& session_id,
                               const std::vector<uint8_t>& signature,
                               ::DBus::Error& error);  // NOLINT - refs
  virtual void VerifyCancel(const std::vector<uint8_t>& isolate_credential,
                            const uint64_t& session_id,
                            ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t VerifyRecoverInit(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const uint64_t& mechanism_type,
      const std::vector<uint8_t>& mechanism_parameter,
      const uint64_t& key_handle,
      ::DBus::Error& error);  // NOLINT - refs
  virtual void VerifyRecover(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const std::vector<uint8_t>& signature,
      const uint64_t& max_out_length,
      uint64_t& actual_out_length,  // NOLINT - refs
      std::vector<uint8_t>& data,  // NOLINT - refs
      uint32_t& result,  // NOLINT - refs
      ::DBus::Error& error);  // NOLINT - refs
  virtual void DigestEncryptUpdate(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const std::vector<uint8_t>& data_in,
      const uint64_t& max_out_length,
      uint64_t& actual_out_length,  // NOLINT - refs
      std::vector<uint8_t>& data_out,  // NOLINT - refs
      uint32_t& result,  // NOLINT - refs
      ::DBus::Error& error);  // NOLINT - refs
  virtual void DecryptDigestUpdate(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const std::vector<uint8_t>& data_in,
      const uint64_t& max_out_length,
      uint64_t& actual_out_length,  // NOLINT - refs
      std::vector<uint8_t>& data_out,  // NOLINT - refs
      uint32_t& result,  // NOLINT - refs
      ::DBus::Error& error);  // NOLINT - refs
  virtual void SignEncryptUpdate(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const std::vector<uint8_t>& data_in,
      const uint64_t& max_out_length,
      uint64_t& actual_out_length,  // NOLINT - refs
      std::vector<uint8_t>& data_out,  // NOLINT - refs
      uint32_t& result,  // NOLINT - refs
      ::DBus::Error& error);  // NOLINT - refs
  virtual void DecryptVerifyUpdate(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const std::vector<uint8_t>& data_in,
      const uint64_t& max_out_length,
      uint64_t& actual_out_length,  // NOLINT - refs
      std::vector<uint8_t>& data_out,  // NOLINT - refs
      uint32_t& result,  // NOLINT - refs
      ::DBus::Error& error);  // NOLINT - refs
  virtual void GenerateKey(const std::vector<uint8_t>& isolate_credential,
                           const uint64_t& session_id,
                           const uint64_t& mechanism_type,
                           const std::vector<uint8_t>& mechanism_parameter,
                           const std::vector<uint8_t>& attributes,
                           uint64_t& key_handle,  // NOLINT - refs
                           uint32_t& result,  // NOLINT - refs
                           ::DBus::Error& error);  // NOLINT - refs
  virtual void GenerateKeyPair(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const uint64_t& mechanism_type,
      const std::vector<uint8_t>& mechanism_parameter,
      const std::vector<uint8_t>& public_attributes,
      const std::vector<uint8_t>& private_attributes,
      uint64_t& public_key_handle,  // NOLINT - refs
      uint64_t& private_key_handle,  // NOLINT - refs
      uint32_t& result,  // NOLINT - refs
      ::DBus::Error& error);  // NOLINT - refs
  virtual void WrapKey(const std::vector<uint8_t>& isolate_credential,
                       const uint64_t& session_id,
                       const uint64_t& mechanism_type,
                       const std::vector<uint8_t>& mechanism_parameter,
                       const uint64_t& wrapping_key_handle,
                       const uint64_t& key_handle,
                       const uint64_t& max_out_length,
                       uint64_t& actual_out_length,  // NOLINT - refs
                       std::vector<uint8_t>& wrapped_key,  // NOLINT - refs
                       uint32_t& result,  // NOLINT - refs
                       ::DBus::Error& error);  // NOLINT - refs
  virtual void UnwrapKey(const std::vector<uint8_t>& isolate_credential,
                         const uint64_t& session_id,
                         const uint64_t& mechanism_type,
                         const std::vector<uint8_t>& mechanism_parameter,
                         const uint64_t& wrapping_key_handle,
                         const std::vector<uint8_t>& wrapped_key,
                         const std::vector<uint8_t>& attributes,
                         uint64_t& key_handle,  // NOLINT - refs
                         uint32_t& result,  // NOLINT - refs
                         ::DBus::Error& error);  // NOLINT - refs
  virtual void DeriveKey(const std::vector<uint8_t>& isolate_credential,
                         const uint64_t& session_id,
                         const uint64_t& mechanism_type,
                         const std::vector<uint8_t>& mechanism_parameter,
                         const uint64_t& base_key_handle,
                         const std::vector<uint8_t>& attributes,
                         uint64_t& key_handle,  // NOLINT - refs
                         uint32_t& result,  // NOLINT - refs
                         ::DBus::Error& error);  // NOLINT - refs
  virtual uint32_t SeedRandom(const std::vector<uint8_t>& isolate_credential,
                              const uint64_t& session_id,
                              const std::vector<uint8_t>& seed,
                              ::DBus::Error& error);  // NOLINT - refs
  virtual void GenerateRandom(const std::vector<uint8_t>& isolate_credential,
                              const uint64_t& session_id,
                              const uint64_t& num_bytes,
                              std::vector<uint8_t>& random_data,  // NOLINT - refs
                              uint32_t& result,  // NOLINT - refs
                              ::DBus::Error& error);  // NOLINT - refs

  // These methods are generated by the Linux dbus library.
  virtual void OpenIsolate(const std::vector<uint8_t>& isolate_credential_in,
                           std::vector<uint8_t>& isolate_credential_out,  // NOLINT - refs
                           bool& new_isolate_created,  // NOLINT - refs
                           bool& result);  // NOLINT - refs
  virtual void CloseIsolate(const std::vector<uint8_t>& isolate_credential);
  virtual void LoadToken(const std::vector<uint8_t>& isolate_credential,
                         const std::string& path,
                         const std::vector<uint8_t>& auth_data,
                         const std::string& label,
                         uint64_t& slot_id,  // NOLINT - refs
                         bool& result);  // NOLINT - refs
  virtual void UnloadToken(const std::vector<uint8_t>& isolate_credential,
                           const std::string& path);
  virtual void ChangeTokenAuthData(const std::string& path,
                                   const std::vector<uint8_t>& old_auth_data,
                                   const std::vector<uint8_t>& new_auth_data);
  virtual void GetTokenPath(const std::vector<uint8_t>& isolate_credential,
                            const uint64_t& slot_id,
                            std::string& path,  // NOLINT - refs
                            bool& result);  // NOLINT - refs
  virtual void SetLogLevel(const int32_t& level);
  virtual void GetSlotList(const std::vector<uint8_t>& isolate_credential,
                           const bool& token_present,
                           std::vector<uint64_t>& slot_list,  // NOLINT - refs
                           uint32_t& result);  // NOLINT - refs
  virtual void GetSlotInfo(const std::vector<uint8_t>& isolate_credential,
                           const uint64_t& slot_id,
                           std::vector<uint8_t>& slot_description,  // NOLINT - refs
                           std::vector<uint8_t>& manufacturer_id,  // NOLINT - refs
                           uint64_t& flags,  // NOLINT - refs
                           uint8_t& hardware_version_major,  // NOLINT - refs
                           uint8_t& hardware_version_minor,  // NOLINT - refs
                           uint8_t& firmware_version_major,  // NOLINT - refs
                           uint8_t& firmware_version_minor,  // NOLINT - refs
                           uint32_t& result);  // NOLINT - refs
  virtual void GetTokenInfo(const std::vector<uint8_t>& isolate_credential,
                            const uint64_t& slot_id,
                            std::vector<uint8_t>& label,  // NOLINT - refs
                            std::vector<uint8_t>& manufacturer_id,  // NOLINT - refs
                            std::vector<uint8_t>& model,  // NOLINT - refs
                            std::vector<uint8_t>& serial_number,  // NOLINT - refs
                            uint64_t& flags,  // NOLINT - refs
                            uint64_t& max_session_count,  // NOLINT - refs
                            uint64_t& session_count,  // NOLINT - refs
                            uint64_t& max_session_count_rw,  // NOLINT - refs
                            uint64_t& session_count_rw,  // NOLINT - refs
                            uint64_t& max_pin_len,  // NOLINT - refs
                            uint64_t& min_pin_len,  // NOLINT - refs
                            uint64_t& total_public_memory,  // NOLINT - refs
                            uint64_t& free_public_memory,  // NOLINT - refs
                            uint64_t& total_private_memory,  // NOLINT - refs
                            uint64_t& free_private_memory,  // NOLINT - refs
                            uint8_t& hardware_version_major,  // NOLINT - refs
                            uint8_t& hardware_version_minor,  // NOLINT - refs
                            uint8_t& firmware_version_major,  // NOLINT - refs
                            uint8_t& firmware_version_minor,  // NOLINT - refs
                            uint32_t& result);  // NOLINT - refs
  virtual void GetMechanismList(const std::vector<uint8_t>& isolate_credential,
                                const uint64_t& slot_id,
                                std::vector<uint64_t>& mechanism_list,  // NOLINT - refs
                                uint32_t& result);  // NOLINT - refs
  virtual void GetMechanismInfo(const std::vector<uint8_t>& isolate_credential,
                                const uint64_t& slot_id,
                                const uint64_t& mechanism_type,
                                uint64_t& min_key_size,  // NOLINT - refs
                                uint64_t& max_key_size,  // NOLINT - refs
                                uint64_t& flags,  // NOLINT - refs
                                uint32_t& result);  // NOLINT - refs
  virtual uint32_t InitToken(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& slot_id,
                             const bool& use_null_pin,
                             const std::string& optional_so_pin,
                             const std::vector<uint8_t>& new_token_label);
  virtual uint32_t InitPIN(const std::vector<uint8_t>& isolate_credential,
                           const uint64_t& session_id,
                           const bool& use_null_pin,
                           const std::string& optional_user_pin);
  virtual uint32_t SetPIN(const std::vector<uint8_t>& isolate_credential,
                          const uint64_t& session_id,
                          const bool& use_null_old_pin,
                          const std::string& optional_old_pin,
                          const bool& use_null_new_pin,
                          const std::string& optional_new_pin);
  virtual void OpenSession(const std::vector<uint8_t>& isolate_credential,
                           const uint64_t& slot_id, const uint64_t& flags,
                           uint64_t& session_id, uint32_t& result);  // NOLINT - refs
  virtual uint32_t CloseSession(const std::vector<uint8_t>& isolate_credential,
                                const uint64_t& session_id);
  virtual uint32_t CloseAllSessions(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& slot_id);
  virtual void GetSessionInfo(const std::vector<uint8_t>& isolate_credential,
                              const uint64_t& session_id,
                              uint64_t& slot_id,  // NOLINT - refs
                              uint64_t& state,  // NOLINT - refs
                              uint64_t& flags,  // NOLINT - refs
                              uint64_t& device_error,  // NOLINT - refs
                              uint32_t& result);  // NOLINT - refs
  virtual void GetOperationState(const std::vector<uint8_t>& isolate_credential,
                                 const uint64_t& session_id,
                                 std::vector<uint8_t>& operation_state,  // NOLINT - refs
                                 uint32_t& result);  // NOLINT - refs
  virtual uint32_t SetOperationState(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const std::vector<uint8_t>& operation_state,
      const uint64_t& encryption_key_handle,
      const uint64_t& authentication_key_handle);
  virtual uint32_t Login(const std::vector<uint8_t>& isolate_credential,
                         const uint64_t& session_id,
                         const uint64_t& user_type,
                         const bool& use_null_pin,
                         const std::string& optional_pin);
  virtual uint32_t Logout(const std::vector<uint8_t>& isolate_credential,
                          const uint64_t& session_id);
  virtual void CreateObject(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const std::vector<uint8_t>& attributes,
      uint64_t& new_object_handle,  // NOLINT - refs
      uint32_t& result);  // NOLINT - refs
  virtual void CopyObject(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const uint64_t& object_handle,
      const std::vector<uint8_t>& attributes,
      uint64_t& new_object_handle,  // NOLINT - refs
      uint32_t& result);  // NOLINT - refs
  virtual uint32_t DestroyObject(const std::vector<uint8_t>& isolate_credential,
                                 const uint64_t& session_id,
                                 const uint64_t& object_handle);
  virtual void GetObjectSize(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& session_id,
                             const uint64_t& object_handle,
                             uint64_t& object_size,  // NOLINT - refs
                             uint32_t& result);  // NOLINT - refs
  virtual void GetAttributeValue(const std::vector<uint8_t>& isolate_credential,
                                 const uint64_t& session_id,
                                 const uint64_t& object_handle,
                                 const std::vector<uint8_t>& attributes_in,
                                 std::vector<uint8_t>& attributes_out,  // NOLINT - refs
                                 uint32_t& result);  // NOLINT - refs
  virtual uint32_t SetAttributeValue(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const uint64_t& object_handle,
      const std::vector<uint8_t>& attributes);
  virtual uint32_t FindObjectsInit(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const std::vector<uint8_t>& attributes);
  virtual void FindObjects(const std::vector<uint8_t>& isolate_credential,
                           const uint64_t& session_id,
                           const uint64_t& max_object_count,
                           std::vector<uint64_t>& object_list,  // NOLINT - refs
                           uint32_t& result);  // NOLINT - refs
  virtual uint32_t FindObjectsFinal(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id);
  virtual uint32_t EncryptInit(const std::vector<uint8_t>& isolate_credential,
                               const uint64_t& session_id,
                               const uint64_t& mechanism_type,
                               const std::vector<uint8_t>& mechanism_parameter,
                               const uint64_t& key_handle);
  virtual void Encrypt(const std::vector<uint8_t>& isolate_credential,
                       const uint64_t& session_id,
                       const std::vector<uint8_t>& data_in,
                       const uint64_t& max_out_length,
                       uint64_t& actual_out_length,  // NOLINT - refs
                       std::vector<uint8_t>& data_out,  // NOLINT - refs
                       uint32_t& result);  // NOLINT - refs
  virtual void EncryptUpdate(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& session_id,
                             const std::vector<uint8_t>& data_in,
                             const uint64_t& max_out_length,
                             uint64_t& actual_out_length,  // NOLINT - refs
                             std::vector<uint8_t>& data_out,  // NOLINT - refs
                             uint32_t& result);  // NOLINT - refs
  virtual void EncryptFinal(const std::vector<uint8_t>& isolate_credential,
                            const uint64_t& session_id,
                            const uint64_t& max_out_length,
                            uint64_t& actual_out_length,  // NOLINT - refs
                            std::vector<uint8_t>& data_out,  // NOLINT - refs
                            uint32_t& result);  // NOLINT - refs
  virtual void EncryptCancel(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& session_id);
  virtual uint32_t DecryptInit(const std::vector<uint8_t>& isolate_credential,
                               const uint64_t& session_id,
                               const uint64_t& mechanism_type,
                               const std::vector<uint8_t>& mechanism_parameter,
                               const uint64_t& key_handle);
  virtual void Decrypt(const std::vector<uint8_t>& isolate_credential,
                       const uint64_t& session_id,
                       const std::vector<uint8_t>& data_in,
                       const uint64_t& max_out_length,
                       uint64_t& actual_out_length,  // NOLINT - refs
                       std::vector<uint8_t>& data_out,  // NOLINT - refs
                       uint32_t& result);  // NOLINT - refs
  virtual void DecryptUpdate(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& session_id,
                             const std::vector<uint8_t>& data_in,
                             const uint64_t& max_out_length,
                             uint64_t& actual_out_length,  // NOLINT - refs
                             std::vector<uint8_t>& data_out,  // NOLINT - refs
                             uint32_t& result);  // NOLINT - refs
  virtual void DecryptFinal(const std::vector<uint8_t>& isolate_credential,
                            const uint64_t& session_id,
                            const uint64_t& max_out_length,
                            uint64_t& actual_out_length,  // NOLINT - refs
                            std::vector<uint8_t>& data_out,  // NOLINT - refs
                            uint32_t& result);  // NOLINT - refs
  virtual void DecryptCancel(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& session_id);
  virtual uint32_t DigestInit(const std::vector<uint8_t>& isolate_credential,
                              const uint64_t& session_id,
                              const uint64_t& mechanism_type,
                              const std::vector<uint8_t>& mechanism_parameter);
  virtual void Digest(const std::vector<uint8_t>& isolate_credential,
                      const uint64_t& session_id,
                      const std::vector<uint8_t>& data_in,
                      const uint64_t& max_out_length,
                      uint64_t& actual_out_length,  // NOLINT - refs
                      std::vector<uint8_t>& digest,  // NOLINT - refs
                      uint32_t& result);  // NOLINT - refs
  virtual uint32_t DigestUpdate(const std::vector<uint8_t>& isolate_credential,
                                const uint64_t& session_id,
                                const std::vector<uint8_t>& data_in);
  virtual uint32_t DigestKey(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& session_id,
                             const uint64_t& key_handle);
  virtual void DigestFinal(const std::vector<uint8_t>& isolate_credential,
                           const uint64_t& session_id,
                           const uint64_t& max_out_length,
                           uint64_t& actual_out_length,  // NOLINT - refs
                           std::vector<uint8_t>& digest,  // NOLINT - refs
                           uint32_t& result);  // NOLINT - refs
  virtual void DigestCancel(const std::vector<uint8_t>& isolate_credential,
                            const uint64_t& session_id);
  virtual uint32_t SignInit(const std::vector<uint8_t>& isolate_credential,
                            const uint64_t& session_id,
                            const uint64_t& mechanism_type,
                            const std::vector<uint8_t>& mechanism_parameter,
                            const uint64_t& key_handle);
  virtual void Sign(const std::vector<uint8_t>& isolate_credential,
                    const uint64_t& session_id,
                    const std::vector<uint8_t>& data,
                    const uint64_t& max_out_length,
                    uint64_t& actual_out_length,  // NOLINT - refs
                    std::vector<uint8_t>& signature,  // NOLINT - refs
                    uint32_t& result);  // NOLINT - refs
  virtual uint32_t SignUpdate(const std::vector<uint8_t>& isolate_credential,
                              const uint64_t& session_id,
                              const std::vector<uint8_t>& data_part);
  virtual void SignFinal(const std::vector<uint8_t>& isolate_credential,
                         const uint64_t& session_id,
                         const uint64_t& max_out_length,
                         uint64_t& actual_out_length,  // NOLINT - refs
                         std::vector<uint8_t>& signature,  // NOLINT - refs
                         uint32_t& result);  // NOLINT - refs
  virtual void SignCancel(const std::vector<uint8_t>& isolate_credential,
                          const uint64_t& session_id);
  virtual uint32_t SignRecoverInit(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const uint64_t& mechanism_type,
      const std::vector<uint8_t>& mechanism_parameter,
      const uint64_t& key_handle);
  virtual void SignRecover(const std::vector<uint8_t>& isolate_credential,
                           const uint64_t& session_id,
                           const std::vector<uint8_t>& data,
                           const uint64_t& max_out_length,
                           uint64_t& actual_out_length,  // NOLINT - refs
                           std::vector<uint8_t>& signature,  // NOLINT - refs
                           uint32_t& result);  // NOLINT - refs
  virtual uint32_t VerifyInit(const std::vector<uint8_t>& isolate_credential,
                              const uint64_t& session_id,
                              const uint64_t& mechanism_type,
                              const std::vector<uint8_t>& mechanism_parameter,
                              const uint64_t& key_handle);
  virtual uint32_t Verify(const std::vector<uint8_t>& isolate_credential,
                          const uint64_t& session_id,
                          const std::vector<uint8_t>& data,
                          const std::vector<uint8_t>& signature);
  virtual uint32_t VerifyUpdate(const std::vector<uint8_t>& isolate_credential,
                                const uint64_t& session_id,
                                const std::vector<uint8_t>& data_part);
  virtual uint32_t VerifyFinal(const std::vector<uint8_t>& isolate_credential,
                               const uint64_t& session_id,
                               const std::vector<uint8_t>& signature);
  virtual void VerifyCancel(const std::vector<uint8_t>& isolate_credential,
                            const uint64_t& session_id);
  virtual uint32_t VerifyRecoverInit(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const uint64_t& mechanism_type,
      const std::vector<uint8_t>& mechanism_parameter,
      const uint64_t& key_handle);
  virtual void VerifyRecover(const std::vector<uint8_t>& isolate_credential,
                             const uint64_t& session_id,
                             const std::vector<uint8_t>& signature,
                             const uint64_t& max_out_length,
                             uint64_t& actual_out_length,  // NOLINT - refs
                             std::vector<uint8_t>& data,  // NOLINT - refs
                             uint32_t& result);  // NOLINT - refs
  virtual void DigestEncryptUpdate(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const std::vector<uint8_t>& data_in,
      const uint64_t& max_out_length,
      uint64_t& actual_out_length,  // NOLINT - refs
      std::vector<uint8_t>& data_out,  // NOLINT - refs
      uint32_t& result);  // NOLINT - refs
  virtual void DecryptDigestUpdate(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const std::vector<uint8_t>& data_in,
      const uint64_t& max_out_length,
      uint64_t& actual_out_length,  // NOLINT - refs
      std::vector<uint8_t>& data_out,  // NOLINT - refs
      uint32_t& result);  // NOLINT - refs
  virtual void SignEncryptUpdate(const std::vector<uint8_t>& isolate_credential,
                                 const uint64_t& session_id,
                                 const std::vector<uint8_t>& data_in,
                                 const uint64_t& max_out_length,
                                 uint64_t& actual_out_length,  // NOLINT - refs
                                 std::vector<uint8_t>& data_out,  // NOLINT - refs
                                 uint32_t& result);  // NOLINT - refs
  virtual void DecryptVerifyUpdate(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const std::vector<uint8_t>& data_in,
      const uint64_t& max_out_length,
      uint64_t& actual_out_length,  // NOLINT - refs
      std::vector<uint8_t>& data_out,  // NOLINT - refs
      uint32_t& result);  // NOLINT - refs
  virtual void GenerateKey(const std::vector<uint8_t>& isolate_credential,
                           const uint64_t& session_id,
                           const uint64_t& mechanism_type,
                           const std::vector<uint8_t>& mechanism_parameter,
                           const std::vector<uint8_t>& attributes,
                           uint64_t& key_handle,  // NOLINT - refs
                           uint32_t& result);  // NOLINT - refs
  virtual void GenerateKeyPair(
      const std::vector<uint8_t>& isolate_credential,
      const uint64_t& session_id,
      const uint64_t& mechanism_type,
      const std::vector<uint8_t>& mechanism_parameter,
      const std::vector<uint8_t>& public_attributes,
      const std::vector<uint8_t>& private_attributes,
      uint64_t& public_key_handle,  // NOLINT - refs
      uint64_t& private_key_handle,  // NOLINT - refs
      uint32_t& result);  // NOLINT - refs
  virtual void WrapKey(const std::vector<uint8_t>& isolate_credential,
                       const uint64_t& session_id,
                       const uint64_t& mechanism_type,
                       const std::vector<uint8_t>& mechanism_parameter,
                       const uint64_t& wrapping_key_handle,
                       const uint64_t& key_handle,
                       const uint64_t& max_out_length,
                       uint64_t& actual_out_length,  // NOLINT - refs
                       std::vector<uint8_t>& wrapped_key,  // NOLINT - refs
                       uint32_t& result);  // NOLINT - refs
  virtual void UnwrapKey(const std::vector<uint8_t>& isolate_credential,
                         const uint64_t& session_id,
                         const uint64_t& mechanism_type,
                         const std::vector<uint8_t>& mechanism_parameter,
                         const uint64_t& wrapping_key_handle,
                         const std::vector<uint8_t>& wrapped_key,
                         const std::vector<uint8_t>& attributes,
                         uint64_t& key_handle,  // NOLINT - refs
                         uint32_t& result);  // NOLINT - refs
  virtual void DeriveKey(const std::vector<uint8_t>& isolate_credential,
                         const uint64_t& session_id,
                         const uint64_t& mechanism_type,
                         const std::vector<uint8_t>& mechanism_parameter,
                         const uint64_t& base_key_handle,
                         const std::vector<uint8_t>& attributes,
                         uint64_t& key_handle,  // NOLINT - refs
                         uint32_t& result);  // NOLINT - refs
  virtual uint32_t SeedRandom(const std::vector<uint8_t>& isolate_credential,
                              const uint64_t& session_id,
                              const std::vector<uint8_t>& seed);
  virtual void GenerateRandom(const std::vector<uint8_t>& isolate_credential,
                              const uint64_t& session_id,
                              const uint64_t& num_bytes,
                              std::vector<uint8_t>& random_data,  // NOLINT - refs
                              uint32_t& result);  // NOLINT - refs

 private:
  base::Lock* lock_;
  ChapsInterface* service_;
  TokenManagerInterface* token_manager_;

  DISALLOW_COPY_AND_ASSIGN(ChapsAdaptor);
};

}  // namespace chaps
#endif  // CHAPS_CHAPS_ADAPTOR_H_
